# Copyright (C) 2009,2010,2011,2012  Marco Restelli
#
# This file is part of:
#   LDGH -- Local Hybridizable Discontinuous Galerkin toolkit
#
# LDGH is free software: you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# LDGH is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
# License for more details.
#
# You should have received a copy of the GNU General Public License
# along with LDGH. If not, see <http://www.gnu.org/licenses/>.
#
# author: Marco Restelli                   <marco.restelli@gmail.com>


#---------------------------------------------------------
# General comments
#---------------------------------------------------------
# Set the general options for the compilation of LDGH. This file will
# be included by the main makefile, which could be the LDGH makefile
# or a user makefile linking the LDGH library. For this reason, one
# should not use commands like $(shell pwd), which would give
# different results depending on where this file is included. For the
# same reason, relative paths should be also avoided.


#---------------------------------------------------------
# Initializations (do not change these settings!)
#---------------------------------------------------------
LDGH_CC_INCLUDE:=
LDGH_LDFLAGS:=
LDGH_LIBS:=


#-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-
#X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X
#
# Configuration section
#
#X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X
#-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-

#---------------------------------------------------------
# Main Directory
#---------------------------------------------------------
LDGH_DIR:=/home/restelli/release-LDGH/LDGH-r2
#LDGH_DIR:/home/LDGH

#---------------------------------------------------------
# Compiler
#---------------------------------------------------------
# F90 Compiler
LDGH_FC:=ifort
# How to tell the compiler where to look for .mod files
LDGH_MODFLAG:=-I
# C Compiler
LDGH_CC=gcc

#---------------------------------------------------------
# MPI compiler (only necessary if MPI is used)
#---------------------------------------------------------
LDGH_MPI_IMPL:=OpenMPI
LDGH_MPIF90:=mpif90

#---------------------------------------------------------
# Compiler flags
#---------------------------------------------------------
LDGH_FFLAGS:= -g -O0 -check all -stand f03 -warn all -fpe0 -traceback -ftrapuv -fp-stack-check
LDGH_FFLAGS:=$(LDGH_FFLAGS) -heap-arrays
LDGH_FFLAGS:=$(LDGH_FFLAGS) -g
LDGH_FFLAGS:=$(LDGH_FFLAGS) -assume byterecl -assume minus0 -assume noold_maxminloc -assume noold_unit_star -assume noold_xor -assume std_mod_proc_name
LDGH_CFLAGS:= -DDLONG

#---------------------------------------------------------
# Linker
#---------------------------------------------------------
LDGH_LD:=$(LDGH_FC)

#---------------------------------------------------------
# Archive
#---------------------------------------------------------
LDGH_AR:=ar
# With the Intel compiler, xiar can be also used. This indeed is the
# only way to get ipo in the library.
#  LDGH_AR:=$(realpath $(LDGH_FC))
#  LDGH_AR:=$(dir $(LDGH_AR))xiar

#---------------------------------------------------------
# OpenMP
#---------------------------------------------------------
# Note: select the number of threads with
#   export OMP_NUM_THREADS=n
# and optionally set the stack size of each thread with
#   export OMP_STACKSIZE=16M
LDGH_USING_OMP:=Yes
ifeq ($(strip $(LDGH_USING_OMP)),'Yes')
  LDGH_FFLAGS:=$(LDGH_FFLAGS) -openmp
  LDGH_LDFLAGS:=$(LDGH_LDFLAGS) -openmp
else
  # make sure LDGH_USING_OMP is set to either "Yes" or "No", to
  # simplify subsequent checks
  LDGH_USING_OMP:=No
endif

#---------------------------------------------------------
# MPI
#---------------------------------------------------------
LDGH_USING_MPI:=Yes
ifeq ($(strip $(LDGH_USING_OMP)),'Yes')
  # The Fortran compiler is redefined to the MPI wrapper
  ifeq ($(strip $(LDGH_MPI_IMPL)),'mpich2')
    LDGH_FC:=$(LDGH_MPIF90) -f90=$(LDGH_FC)
  else ifeq ($(strip $(LDGH_MPI_IMPL)),'OpenMPI')
    LDGH_FC:=$(LDGH_MPIF90)
  else
    $(error "Please add options for your MPI implementation.")
  endif
else
  # make sure LDGH_USING_MPI is set to either "Yes" or "No", to
  # simplify subsequent checks
  LDGH_USING_MPI:=No
endif

#---------------------------------------------------------
# UMFPACK
#---------------------------------------------------------
LDGH_USING_UMFPACK:=Yes
ifeq ($(strip $(USING_UMFPACK)),'Yes')
  LDGH_LIBS:=$(LDGH_LIBS) -lumfpack -lamd -latllapack -lgfortran
  LDGH_LDFLAGS:=$(LDGH_LDFLAGS) -L/usr/lib64/gcc/x86_64-pc-linux-gnu/4.5.3
else
  # make sure LDGH_USING_UMFPACK is set to either "Yes" or "No", to
  # simplify subsequent checks
  LDGH_USING_UMFPACK:=No
endif

#---------------------------------------------------------
# MUMPS
#---------------------------------------------------------
LDGH_USING_MUMPS:=Yes
ifeq ($(strip $(LDGH_USING_MUMPS)),'Yes')
  ifneq ($(LDGH_USING_MPI),'Yes')
    $(error "To use MUMPS you need MPI.")
  endif
  LDGH_LIBS:=$(LDGH_LIBS) -ldmumps -lmumps_common -lpord            \
          -lparmetis -lmetis                                        \
	  -lptesmumps -lscotcherr -lptscotch -lscotch               \
	  -lscalapack -latllapack                                   \
	  -lmpiblacs -lmpiblacsF77init -lmpiblacs -lf77blas -latlas \
	  -lgfortran -lpthread -lc
  # assuming that most libraries are in standard locations
  LDGH_LDFLAGS:=$(LDGH_LDFLAGS) -L/usr/lib64/gcc/x86_64-pc-linux-gnu/4.5.3
  LDGH_MUMPS_INCLUDE:=
else
  # make sure LDGH_USING_MUMPS is set to either "Yes" or "No", to
  # simplify subsequent checks
  LDGH_USING_MUMPS:=No
endif

#---------------------------------------------------------
# Blas/Lapack (used by MUMPS)
#---------------------------------------------------------
#BLACS_LIBS:=-lmkl_blacs_openmpi_lp64
#MKL_ROOT:=/data/apps/bin/Intel/cltoolkit/Compiler/11.1/073/mkl
#MKL_PATH:=$(MKL_ROOT)/lib/em64t
#MKL_BASE:=-lmkl_intel_lp64 -lmkl_sequential -lmkl_core -lpthread
#
#BLAS_LDFLAGS:=-L$(MKL_PATH)
#BLAS_LIBS:=-lmkl_blas95_lp64 $(MKL_BASE)
#
#BLACS_LDFLAGS:=-L$(MKL_PATH)
#BLACS_LIBS:=$(BLACS_LIBS) $(MKL_BASE)
#
#LAPACK_LDFLAGS:=-L$(MKL_PATH)
#LAPACK_LIBS:=-lmkl_lapack95_lp64 $(MKL_BASE)
#
#SCALAPACK_LDFLAGS:=-L$(MKL_PATH)
#SCALAPACK_LIBS:=-lmkl_scalapack_lp64 -lmkl_solver_lp64_sequential \
#    $(BLACS_LIBS)
#


#-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-
#X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X
#
# End of configuration section
#
#X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X
#-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-


# Subdirectories
LDGH_SRCDIR  :=$(LDGH_DIR)/src
LDGH_BUILDDIR:=$(LDGH_DIR)/build
LDGH_LIBDIR  :=$(LDGH_DIR)/lib
LDGH_BINDIR  :=$(LDGH_DIR)/bin

